﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="ThietBiSo.LinQDB" %>
<%@ Import Namespace="ThietBiSo.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Website - bảng điều khiển
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        function popupURL(url, width, height) {
            var left = (screen.width - width) / 2;
            var top = (screen.height - height) / 2;
            window.open(url, 'NapCoin', 'left=' + left + 'px,top=' + top + 'px,width=' + width + 'px,height=' + height + 'px,location=no,scrollbars=yes,toolbar=no,resizable=yes,')
        }
        function getUrlVars() {
            var vars = {};
            var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
                vars[key] = value;
            });
            return vars;
        }
        $().ready(function () {
           
            $("#btnAdd").click(function () {
                
                    location.href = '<%=Url.Action("Create","danhmuc")%>';

                });

            });

            function danhmuc_delete(ma) {
                var cnf = window.confirm("Bạn chắc chắn xóa?");
                if (cnf) {
                    $.ajax({
                        type: "POST",
                        url: '<%=Url.Action("Delete") %>',
                        cache: false,
                        async: false,
                        dataType: "json",
                        data: { ma: ma },
                        success: function (result) {
                            if (result.length == 0) { // ko tồn tại                        
                                //                            alert("Xóa dữ liệu thành công.");
                                window.location.reload();
                            }
                            else {
                                alert(result);
                            }
                        }
                    });
                }

            }
            function danhmuc_hienthi(ma) {

                $.ajax({
                    type: "POST",
                    url: '<%=Url.Action("HienThi") %>',
                    cache: false,
                    async: false,
                    dataType: "json",
                    data: { ma: ma },
                    success: function (result) {
                    }
                });
            }

    </script>
    <table width="100%" cellpadding="2" cellspacing="0" border="0">
        <tr>
            <td>
                <table width="100%">
                    <tr>
                        <td class="">
                            <input type="button" value="Thêm danh mục" id="btnAdd" />
                        </td>
                        <td align="right">
                            <%: Html.ActionLink("Quay lại", "quantri", "Admin", null, new { @class = "" })%>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
      <%--  <tr>
            <td align="left">
                Chọn loại danh mục:
                <%= Html.DropDownList("cbNhom", ViewData["group"] as SelectList)%>
            </td>
        </tr>--%>
        <tr>
            <td colspan="2">
                <table id="bang_admin" class="tbl colorize" width="100%" border="0">
                    <tbody>
                        <tr>
                            <th style="text-align: center" width="50">
                                TT
                            </th>
                           
                            <th align="left">
                                Danh mục
                            </th>
                            <th align="left">
                                Danh mục con
                            </th>
                            <th align="center" style="width: 100px; text-align: center;">
                                Hiển thị
                            </th>
                            <th align="center" width="30">
                                Xóa
                            </th>
                        </tr>
                    </tbody>
                    <tbody>
                        <% foreach (DanhMuc sp in (List<DanhMuc>)ViewData["danhmucs"])
                           {               
                        %>
                        <tr class="tb_hienthi">
                            <td align="center" valign="middle">
                                <input type="text" disabled="disabled" autocomplete="off" class="orderbox" value="<%:sp.ThuTu %>"
                                    maxlength="4" id="thutu" style="width: 20px;" />&nbsp;
                            </td>
                           
                            <td align="left">
                                <a href="<%=Url.Action("Edit","danhmuc", new { id = sp.MaDanhMuc} ) %>">
                                    <%: sp.TenDanhMuc%></a>
                            </td>
                            <td>
                                <div onclick="popupURL('/danhmuc/danhmuccon?id=<%:sp.MaDanhMuc %>',700,1000)" style="cursor: pointer;
                                    color: Blue">
                                    Danh mục con
                                </div>
                            </td>
                            <td align="center">
                                <%if (sp.HienThi == false)
                                  {
                                %>
                                <a href="javascript:danhmuc_hienthi(<%:sp.MaDanhMuc%>);">
                                    <input type="checkbox" />
                                </a>
                                <%}
                                  else
                                  {%>
                                <a href="javascript:danhmuc_hienthi(<%:sp.MaDanhMuc%>);">
                                    <input type="checkbox" checked="checked" /></a>
                                <%} %>
                            </td>
                            <td align="center">
                                <a href="javascript:danhmuc_delete(<%:sp.MaDanhMuc %>);">
                                    <img src="../../Content/imagesAdmin/images/pic_trash.gif" alt="" /></a>
                            </td>
                        </tr>
                        <% } %>
                    </tbody>
                </table>
            </td>
        </tr>
        <tr>
            <td style="text-align: center; clear: both; width: 100%; padding: 20px 0 10px 0;">
                <% if ((string)ViewData["pageLinks"] != "")
                   { %>
                <%= ViewData["pageLinks"] %>
                <% } %>Tổng: <strong>
                    <%= ViewData["total"]%></strong>
            </td>
        </tr>       
    </table>
</asp:Content>
